package guijavacommander.actions;

import guijavacommander.FilePanel;
import guijavacommander.JavaCommander;
import guijavacommander.tasks.CopyFileTask;
import guijavacommander.tasks.FilesThreadDialog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;

/**
 * User: Deady
 * Date: 17.07.2009
 * Time: 10:32:21
 */
public class CopyOldWayAction extends AbstractAction {

    private Log logger = LogFactory.getLog(CopyOldWayAction.class);

    public void actionPerformed(ActionEvent e) {
        JavaCommander cmd = JavaCommander.instance;
        FilePanel active = cmd.getActivePanel();
        FilePanel inactive = cmd.getInactivePanel();

        File[] selected = active.getSelectedFiles();
        File dest = inactive.getCurrentFolder();

        if (JOptionPane.showConfirmDialog(cmd, "Copy "+selected.length+" files to "+dest+"?",
                "Attention", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {

            new FilesThreadDialog(cmd, new CopyFileTask(dest, selected)).execute();
        }

        logger.debug("Refreshing panels");
        active.refresh();
        inactive.refresh();
    }
}
